#!/bin/sh
#default
#venv python  3.7.4
venvDir=/home/qinge/software/venv37
venvPython=$venvDir/bin/python
pythonDir=/home/qinge/Documents/ubuntn/python/study
pythonFileName=app.py
pythonFile=$pythonDir/$pythonFileName
logPath=/home/qinge/Desktop/log.txt
#read launchConfig.json
data=`cat launchConfig.json`
for one in $data
do
  firstOne=`echo $one|cut -c 1`
  if [ $firstOne = '#' ]
  then
    continue
  fi
	varName=`echo $one|cut -d= -f 1`
	varValue=`echo $one|cut -d= -f 2`
	case $varName in
		venvPython)
			venvPython=$varValue
			;;
		pythonFile)
			pythonFile=$varValue
			;;
		logPath)
			logPath=$varValue
			;;
		pythonFileName)
			pythonFileName=$varValue
			;;
		*)
			;;
	esac	
done
#kill old process
pid=`ps -ef|grep python |sed "/$pythonFileName/p" -n |awk '{print $2}'`
if [ ${#pid[@]} -eq 0 ]
then
	echo "now has not this process"	
else       	
	echo $pid
	kill -9 $pid
	echo "kill this process sucess"
fi
#wait 5s 
sleep 5s
#lanch new process
nohup $venvPython $pythonFile runserver --threaded >> $logPath &